<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置<small>权限管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="权限类型" align="center"></el-table-column>
                <el-table-column prop="keyword" label="权限助记码" align="center"></el-table-column>
                <el-table-column prop="description" label="说明" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增权限管理项" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="权限信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="权限类型">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="权限助记码">
                                                <el-select v-model="formData.keyword">
                                                    <el-option label="CHECKITEM_ADD" value="1"></el-option>
                                                    <el-option label="CHECKITEM_DELETE" value="2"></el-option>
                                                    <el-option label="CHECKITEM_EDIT" value="3"></el-option>
                                                    <el-option label="CHECKITEM_QUERY" value="4"></el-option>
                                                    <el-option label="CHECKGROUP_ADD" value="5"></el-option>
                                                    <el-option label="CHECKGROUP_DELETE" value="6"></el-option>
                                                    <el-option label="CHECKGROUP_EDIT" value="7"></el-option>
                                                    <el-option label="CHECKGROUP_QUERY" value="8"></el-option>
                                                    <el-option label="SETMEAL_ADD" value="9"></el-option>
                                                    <el-option label="SETMEAL_DELETE" value="10"></el-option>
                                                    <el-option label="SETMEAL_EDIT" value="11"></el-option>
                                                    <el-option label="SETMEAL_QUERY" value="12"></el-option>
                                                    <el-option label="ORDERSETTING" value="13"></el-option>
                                                    <el-option label="REPORT_VIEW" value="14"></el-option>
                                                    <el-option label="MENU_ADD" value="15"></el-option>
                                                    <el-option label="MENU_DELETE" value="16"></el-option>
                                                    <el-option label="MENU_EDIT" value="17"></el-option>
                                                    <el-option label="MENU_QUERY" value="18"></el-option>
                                                    <el-option label="ROLE_ADD" value="19"></el-option>
                                                    <el-option label="ROLE_DELETE" value="20"></el-option>
                                                    <el-option label="ROLE_EDIT" value="21"></el-option>
                                                    <el-option label="ROLE_QUERY" value="22"></el-option>
                                                    <el-option label="USER_ADD" value="23"></el-option>
                                                    <el-option label="USER_DELETE" value="24"></el-option>
                                                    <el-option label="USER_EDIT" value="25"></el-option>
                                                    <el-option label="USER_QUERY" value="26"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="说明">
                                                <el-input v-model="formData.description" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑检查组" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="权限信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="权限类型">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="权限助记码">
                                                <el-input v-model="formData.keyword"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="说明">
                                                <el-input v-model="formData.description" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:5,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
        },
        created:function() {
            this.findPage();
        },
        methods: {
            // 重置表单
            resetForm() {
                this.formData = {};
            },


            // 弹出添加窗口
            handleCreate() {
                // 先重置数据
                this.resetForm();
                // 显示添加弹窗表单
                this.dialogFormVisible = true;
            },
            //添加
            handleAdd () {
                // 发送请求给后台进行保存数据
                axios.post("/permission/add.do",this.formData).then((resp) => {
                    this.dialogFormVisible = false;
                    if (resp.data.flag){
                        // 如果添加成功
                        this.$message.success(resp.data.message);
                        //重新查询页面,如果添加失败则不用查询页面
                        this.pagination.currentPage = this.pagination.total/this.pagination.pageSize+1;
                        this.findPage();
                    } else {
                        // 如果添加失败
                        this.$message.error(resp.data.message);
                    }
                });
            },


            //分页查询
            findPage() {
                // 封装查询参数
                let param = {
                    currentPage: this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString: this.pagination.queryString

                };
                // 发送ajax请求,进行分页查询
                axios.post("/permission/findPage.do",param).then((resp) => {
                    this.dataList = resp.data.rows;
                    this.pagination.total = resp.data.total;
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },


            // 弹出编辑窗口
            handleUpdate(row) {
                // 先将编辑框显示出来
                this.dialogFormVisible4Edit = true;
                // 然后再回显数据,先根据id去查询检查组
                axios.get("/permission/findById.do?id="+row.id).then((resp) => {
                    // 此请求是根据id查询权限管理
                    if (resp.data.flag){
                        // 将查询到的数据放表单里边
                        this.formData = resp.data.data;
                    } else {
                        this.$message.error("获取数据失败");
                    }
                });
            },
            //编辑
            handleEdit() {
                // 当点击确定的时候就需要去数据库里边进行保存,首先要保存检查组的数据,
                axios.post("/permission/edit.do?",this.formData).then((resp) => {
                    this.dialogFormVisible4Edit = false;
                    if (resp.data.flag){
                        // 如果添加成功
                        this.$message.success(resp.data.message);
                        // 编辑成功则重新查询页面,失败则不用再次查询
                        this.findPage();
                    } else {
                        // 如果添加失败
                        this.$message.error(resp.data.message);
                    }
                });
            },


            // 删除
            handleDelete(row) {
                // 删除操作
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() =>{
                    axios.get("/permission/delete.do?id="+ row.id).then(resp =>{
                        if(resp.data.flag){
                            //删除成功,弹出提示信息
                            this.$message.success(resp.data.message);
                            this.findPage();
                        }else {
                            //删除失败,弹出提示信息
                            this.$message.error(resp.data.message);
                        }
                    });
                }).catch(() =>{
                    this.$message.info("您取消了此次删除操作");
                })
            }
        }
    })
</script>
</html>
